﻿Imports Controller
Imports Entities
Public Class OpcionConsultas
    Private myController As New Controller.NegocioSQL
    Private Sub OpcionConsultas_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        cmbTipoBusqueda.Items.Add("Buscar Por Titulo De Libro ")
        cmbTipoBusqueda.Items.Add("Buscar Por Categoria De Libro ")
        cmbTipoBusqueda.Items.Add("Buscar Morosos ")
        cmbTipoBusqueda.Items.Add("Buscar Por Prestamo ")
        cmbTipoBusqueda.Items.Add("Buscar Personas con tal libro (seleccionar libro)")
        CbModificar.Items.Add("Prestar Libro")
        CbModificar.Items.Add("Introducir devolucion")
        CbModificar.Items.Add("Introducir libro")
        CbModificar.Items.Add("Devolver Libro")
        OFF_COMBOBOX()
    End Sub


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnBuscar.Click
        If cmbTipoBusqueda.Text <> "" And CbModificar.Text <> "" Then
            MessageBox.Show("Solo puedes escojer una opcion", "Alerta", MessageBoxButtons.OK)
            cmbTipoBusqueda.Text = ""
            CbModificar.Text = ""
        End If
        If cmbTipoBusqueda.Text <> "" Then
            Select Case (cmbTipoBusqueda.SelectedIndex)
                Case 0
                    Informacion.LtbInformacion.DataSource = myController.SQLgetLibrosPorTitulo(cmbBuscarPor.SelectedItem)
                    Informacion.Show()
                    OFF_COMBOBOX()
                Case 1
                    Informacion.LtbInformacion.DataSource = myController.SQLgetLibroPorCategoria(cmbBuscarPor.SelectedItem)
                    Informacion.Show()
                    OFF_COMBOBOX()
                Case 2
                    Informacion.LtbInformacion.DataSource = myController.SQLgetMorosos
                    Informacion.Show()
                Case 3
                    Informacion.LtbInformacion.DataSource = myController.SQLgetPrestamo
                    Informacion.Show()
                    OFF_COMBOBOX()
                Case 4
                    Informacion.LtbInformacion.DataSource = myController.SQLgetClientesConTalEjemplar(cmbBuscarPor.SelectedItem)
                    Informacion.Show()
                    OFF_COMBOBOX()
            End Select
        End If
    End Sub

    Private Sub CbBuscar_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbTipoBusqueda.SelectedIndexChanged
        Dim pos As Integer = cmbTipoBusqueda.SelectedIndex
        Select Case pos
            Case 0
                ON_COMBOBOX()
                LIMPIAR_COMBOBOX()
                cmbBuscarPor.Items.AddRange(myController.SQLgetLibros.ToArray)
                Exit Sub
            Case 1
                ON_COMBOBOX()
                LIMPIAR_COMBOBOX()
                cmbBuscarPor.Items.AddRange(myController.SQLgetCategorias().ToArray)
                Exit Sub
            Case 2
                OFF_COMBOBOX()
                Exit Sub
            Case 3
                OFF_COMBOBOX()
                Exit Sub
            Case 4
                ON_COMBOBOX()
                LIMPIAR_COMBOBOX()
                cmbBuscarPor.Items.AddRange(myController.SQLgetLibros.ToArray)
                Exit Sub
        End Select
    End Sub

    Private Sub LIMPIAR_COMBOBOX()
            cmbBuscarPor.Items.Clear()
    End Sub
    Private Sub ON_COMBOBOX()
        If cmbBuscarPor.Visible = False Then
            cmbBuscarPor.Visible = True
            lblBuscarpor.Visible = True
            cmbBuscarPor.Enabled = True
        End If
    End Sub

    Private Sub OFF_COMBOBOX()
        If cmbBuscarPor.Visible = True Then
            cmbBuscarPor.Visible = False
            cmbBuscarPor.Visible = False
            lblBuscarpor.Visible = False
        End If
    End Sub
    Private Sub CbModificar_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CbModificar.SelectedIndexChanged

    End Sub

    Private Sub btnAceptar_Click(sender As Object, e As EventArgs) Handles btnAceptar.Click
        Dim pos As Integer = CbModificar.SelectedIndex
        If CbModificar.Text <> "" Then
            Select Case pos
                Case 0
                    PrestarLibro.Show()
                Case 1
                    DevolverPrestamo.Show()
                Case 2
                    InsertarLibro.Show()
                Case 3
                    DevolverPrestamo.Show()
            End Select
        End If
    End Sub
    Private Sub btnCancelar_Click(sender As Object, e As EventArgs) Handles btnCancelar.Click
        cmbTipoBusqueda.Text = ""
        CbModificar.Text = ""
    End Sub
End Class